﻿using JiveMessenger.Models;
using JiveMessenger.ViewModels;
using JmShared;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using Windows.UI.Xaml;

namespace JiveMessenger.SampleData
{
    public class SampleViewModelNotifications : IViewModelNotifications
    {
        public void Cleanup()
        {
            throw new NotImplementedException();
        }
        private ObservableCollection<VisualNotification> _groupedNotifications;
        public ObservableCollection<VisualNotification> GroupedNotifications
        {
            get
            {
                if (Notifications != null)
                {
                    if (_groupedNotifications == null)
                        _groupedNotifications = CreateVisualNotifications();

                }
                return _groupedNotifications;
            }
            set
            {

            }
        }

        public string AcceptButtonText
        {
            get
            {
                return "Accept";
            }
            set
            {
            }
        }
        public string DeclineButtonText
        {
            get
            {
                return "Decline";
            }
            set
            {
            }
        }
        public bool HaveUnreadNotifications
        {
            get
            {
                return true;
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        private System.Collections.ObjectModel.ObservableCollection<JmShared.NotificationBase> _notifications;
        public System.Collections.ObjectModel.ObservableCollection<JmShared.NotificationBase> Notifications
        {
            get
            {
                if (_notifications == null)
                {
                    var notifications = new List<NotificationBase>();
                    //  var locator = VmHelper.Locator;
                    notifications.Add(new FriendInviteNotification()
                    {
                        IsRead = false,
                        NotificationText = "join plx",
                        SenderUsername = "MyUsername"
                    });
                    notifications.Add(new GroupInviteNotification()
                    {
                        Group = new ChatGroup("1", "TestGroup"),
                        NotificationText = "yoyoyo join",
                        SenderUsername = "Lard McFatty",
                    });
                    //   notifications.Add(new GroupInviteNotification() { IsRead = false, Group = locator.CurrentClient.CurrentUserInfo.ChatGroups.FirstOrDefault(), NotificationText = "join gruppe", SenderUsername = locator.CurrentClient.CurrentUserInfo.UserName });
                    _notifications = new ObservableCollection<NotificationBase>(notifications);
                }
                return _notifications;
            }
            set
            {
                throw new NotImplementedException();
            }
        }


        public GalaSoft.MvvmLight.Command.RelayCommand AcceptInviteCommand
        {
            get
            {
                return null;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public GalaSoft.MvvmLight.Command.RelayCommand DeclineInviteCommand
        {
            get
            {
                return null;
            }
            set
            {
                throw new NotImplementedException();
            }
        }


        public int NotificationCount
        {
            get
            {
                return this.Notifications != null ? this.Notifications.Count : 0;
            }
        }

        private ObservableCollection<VisualNotification> CreateVisualNotifications()
        {
            var groupedNotifications = new ObservableCollection<VisualNotification>();
            var splittedGroups = this.Notifications.ToLookup(x => x.NotificationType);

            foreach (var group in splittedGroups)
            {
                groupedNotifications.Add(new VisualNotification(group.Key, new ObservableCollection<NotificationBase>(group)));
            }
            return groupedNotifications;
        }

    }
}
